'''
Created on Feb 20, 2012

@author: lino possamai www.possamai.it/lino
license: GPL-v3
'''

import sys
import pickle
import random
from inertial import evolution_inertial
from inertial import evolution_inertial_ari
from accelerated import evolution_accelerated
from accelerated import evolution_accelerated_sirens_broadcast
from accelerated import evolution_accelerated_sirens_wordofmouth
from accelerated import evolution_accelerated_sirens_preferential
import networkx as nx
#import cProfile


        
if __name__ == '__main__':
    random.seed()
    path ="/home/lino/Dropbox/sna2012/eclipseworkspace/sna2012/src"
    
    if len(sys.argv)>4:
        filename=sys.argv[1]
        
        file_archi = "%s/%s.archi" % (path,filename.split("/")[-1].split(".")[0])
        file_graph = "%s/%s.graph" % (path,filename.split("/")[-1].split(".")[0])
        
        analisi=int(sys.argv[2])
        tecnica=int(sys.argv[3])
        id_run=int(sys.argv[4])
        
        
        #cProfile.run("evolution_inertial('%s',%d,%d)" % (filename, int(tecnica), int(runs)))
        if analisi==1:
            if tecnica==2:
                evolution_inertial_ari(filename, id_run, file_graph)
            elif tecnica==4:
            	
            else:
                evolution_inertial(filename, tecnica, id_run, file_archi, file_graph)
            
        if analisi==2:  #accelerated 
            if len(sys.argv)<7:
                print "we need more parameters:"
                print "aggiustamento C"
                print "cores"
            else:
                aggiustamento = float(sys.argv[5])
                cores = int (sys.argv[6])
                evolution_accelerated(aggiustamento,filename, tecnica, id_run,file_archi, file_graph, cores)
        if analisi==3 or analisi==4 or analisi==5:  #accelerated with sirens (broadcast)

            if len(sys.argv)<10:
                print "we need more parameters:"
                print "1) aggiustamento C"
                print "2) number of sirens to use"
                print "3) attractivity"
                print "4) length of time sirens are used"
                print "5) cores"
            else:
                aggiustamento = float(sys.argv[5])
                nsir = int(sys.argv[6])
                attractivity = float(sys.argv[7])
                time = int(sys.argv[8])
                cores = int(sys.argv[9])
                if analisi==3:
                    evolution_accelerated_sirens_broadcast(aggiustamento, filename, tecnica,id_run,nsir,attractivity, time,file_archi, file_graph,cores)
                if analisi==4:
                    evolution_accelerated_sirens_wordofmouth(aggiustamento, filename, tecnica,id_run,nsir,attractivity, time,file_archi, file_graph,cores)
                if analisi==5:
              	    evolution_accelerated_sirens_preferential(aggiustamento, filename, tecnica,id_run,nsir,attractivity, time,file_archi, file_graph,cores)
             
    else:
        print "not enough parameters."
        print "1) pajek filename"
        print "2) 1=inertial, 2=accelerated, 3=accelerated + sirens (bro), 4=accelerated + sirens (pass), 5=accelerated + sirens (pref) "
        print "3) 1=random, 2=aristocratic, 3=social, 4=random walk"
        print "4) run id"
